﻿using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
using System.ComponentModel;
using System;
namespace WebApp
{
    public class MyLinq: IDAO
    {
        private LinqDataContext linq = new LinqDataContext();

        public List<string> getCountry()
        {
            List<string> list = new List<string>();

            list.Add("MyLinq: ");

            LinqDataContext linq = new LinqDataContext();
            var country = from p in linq.countries select p;

            foreach (var Result in country)
                list.Add( Result.name);
            
            return list;
        }

        public user checkLogin(string username, string password)
        {
            var v = from u in linq.users where u.login == username && u.password == password select u;
            if( v.Count() >= 1)
                return v.First();
            else
                return null;
        }

        public country getCountry(int id)
        {
            var v = from c in linq.countries where c.id == id select c;
            if (v.Count() == 1)
                return v.First();
            else
                return null;
        }

        public trip getTrip(int id)
        {
            var v = from t in linq.trips where t.id == id select t;
            if (v.Count() == 1)
                return v.First();
            else
                return null;
        }

        #region IDAO Members

        List<country> IDAO.getCountry()
        {
            var v = from c in linq.countries select c;
            return v.ToList();
        }

        List<trip> IDAO.getTrips(int min_price, int max_price, int country, System.DateTime date_begin, System.DateTime date_end)
        {
            List<trip> list = new List<trip>();


            var v = from p in linq.trips where p.price > min_price select p;

            foreach (trip tr in v)
                list.Add(tr);
            //var v = from p in linq.trips where p.price > min_price select new Offerts(p.price, p.price, p.id_country, p.start_date, p.dead_line);
            return list;
        }
        #endregion
        public List<reservation> getReservations(int person)
        {
            List<reservation> list = new List<reservation>();

            var v = from r in linq.reservations where r.id_person == person select r;

            foreach (reservation res in v)
            {
                list.Add(res);
            }
            return list;
        }

        int IDAO.addUser(string login, string password, string email)
        {

            return -1;
        }

        void IDAO.addReservation(int trip_id, int person_id, int company_id, int person_count)
        {
        }
}


}